
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <title>学生信息</title>
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-1.11.3.min.js"></script>

    <link rel="stylesheet" href="<%=basePath%>static/css/bootstrap-theme.css">
    <%--    <link rel="stylesheet" href="<%=basePath%>static/css/pintuer.css">--%>


    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/jqPaginator.js"></script>
</head>
<body >
<div id="window" style="position: absolute;left: 30%;top:20%;width: 400px;height: 370px;background-color: #a6e1ec;display: none;">
    <center>
        <input type="hidden" name="id" id="id">
        <span >学生id：  </span><input type="text" name="sid" id="sid" readonly = "true"><br>
        <span>学生编号：</span><input type="text" name="sno" id="sno" readonly = "true"><br>
        <span >学生姓名：</span><input type="text" name="sname" id="sname" readonly = "true"><br>
        <span >学生密码：</span><input type="text" name="spwd" id="spwd" ><br>
        <span>入学日期：</span><input type="text" name="entrancetime" id="entrancetime" readonly = "true"><br>
        <span>地址：    </span>    <input type="text" name="address" id="address"><br>
        <input type="button" value="修改" onclick="updateStudent()" >
        <input type="reset" value="重置">
        <input type="reset" value="关闭" onclick="closeWindow()">
    </center>
</div>
<table class="table table-hover" border="1" width="50%">
    <tr>
        <td>学生id</td>
        <td>学生编号</td>
        <td>学生姓名</td>
        <td>学生密码</td>
        <td>入学日期</td>
        <td>地址</td>
        <td colspan="2">操作</td>

    </tr>
    <tbody id="tb">
    </tbody>
</table>
</body>

<script>
    //文档加载后要执行的函数
    $(document).ready(function () {
        loadData();
    });

    function loadData() {
//jquery的ajax请求方法

        var mno= '<%=session.getAttribute("userId")%>';
        $.ajax({
            url: "<%=basePath%>manage/queryStudentAll",
            async: false,//同步请求（默认）
            type: "POST",
            dataType: "json",
            data: {"mno":mno},
            success: function (data) {
                console.log(data);
//使用jquery形式遍历
// $.each(data.list, function (n, val) {
                $("#tb").html("");
                if(data.length>0){
                    //使用jquery形式遍历
                    $.each(data,function(n,val){
                        var html = "";
                        html += "<tr>" +
                            "<td>" + val.sid+ "</td>" +
                            "<td>" + val.sno+ "</td>" +
                            "<td>" + val.sname + "</td>" +
                            "<td>" + val.spwd+ "</td>" +
                            "<td>" + val.entrancetime+ "</td>" +
                            "<td>" + val.address + "</td>" +
                            "<td>" + " "+ "</td>" +
                            "<td>" +
                            "<button class=\"button border-main icon-plus-square-o\"  type='button' onclick='updateWindow(this)'>修改</button>" +
                            // "<button class=\"button border-main icon-plus-square-o\"  type='button' onclick='delWindow("+val.s_id+")'>删除</button>" +
                            "</td>" +
                            "</tr>";
                        $("#tb").append(html);
                    });
                }else{
                    $("#tb").append("<tr><td colspan=8 align=\"center\">暂时没有数据哦，快去添加一条吧</td></tr>");
                }
            },
            error:function(){
                alert("服务器出错！");
            }
        });

    }

    //打开修改的模态框
    function updateWindow(obj) {
//显示修改的模态框
        $("#window").show();
//获取当前选中行的所有数据
        var sid = $(obj).parent().parent().find("td").eq(0).text()
        var sno = $(obj).parent().parent().find("td").eq(1).text()
        var sname = $(obj).parent().parent().find("td").eq(2).text()
        var spwd = $(obj).parent().parent().find("td").eq(3).text()
        var entrancetime = $(obj).parent().parent().find("td").eq(4).text()
        var address= $(obj).parent().parent().find("td").eq(5).text()
        // var sdmmId = $(obj).parent().parent().find("td").eq(8).text()
        // var scClassId = $(obj).parent().parent().find("td").eq(9).text()
        // var isordelete = $(obj).parent().parent().find("td").eq(10).text()
        // var studentRole = $(obj).parent().parent().find("td").eq(11).text()

        console.log("locked=" + id)
//把选中行的数据复制给修改框里的表单元素
        $("#sid").val(sid);
        $("#sno").val(sno);
        $("#sname").val(sname);
        $("#spwd").val(spwd);
        $("#entrancetime").val(entrancetime);
        $("#address").val(address);

        // $("#sdmmId").val(sdmmId);
        // $("#scClassId").val(scClassId);
        // $("#isordelete").val(isordelete);
        // $("#studentRole").val(studentRole);

    }

    //修改操作
    function updateStudent() {


//获取文本框的值

        var sid = $("#sid").val();
        var sno = $("#sno").val();
        var sname = $("#sname").val();
        var spwd = $("#spwd").val();
        var entrancetime = $("#entrancetime").val();
        var address = $("#address").val();



        $.ajax({
            url: "<%=basePath%>manage/updateStudent",
            type: "Post",
            data: {
                "sno":sno,
                "spwd": spwd,
                "address": address,
            },
            dataType: "json",//传json
            success: function (data) {
                console.log(data)
                alert("修改成功")
//关闭模态框
                $("#window").hide();
//刷新
// loadData();
                window.location.reload();
            }
        })

    }

    function closeWindow() {
        $("#window").hide();
    }

</script>
</body>
</html>
